<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2020/1/6
 * Time: 15:54
 */
namespace app\controller;

use app\BaseController;
use think\facade\Db;

class Data extends BaseController{

    public function index(){

     // $result =  Db::table("mall_demo")->where("id",1)->find();

      // 通过容器的方式来处理

        //$result =  app("db")->table("mall_demo")->where("id",2)->find();
        $result =  Db::table("mall_demo")->order("id","desc")
            ->page(1,2)->select();

      dump($result);
    }

    public function demo(){

        $data = [
            "title"=>"singwa7",
            "content"=>"来自北京",
            "category_id"=>3,
            "create_time"=>time(),
            "update_time"=>time(),
            "status"=>1
            ];
        $result = Db::table("mall_demo")->insert($data);
        dump($result);
    }

    public function model1(){

        $result = \app\model\Demo::find(2);
        dump($result->toArray());
    }

    public function model2(){

        $modelObj = new \app\model\Demo();

       $data =  $modelObj->where("category_id",1)->select();

       foreach ($data as $val){
           dump($val['content']);
           dump($val->status);
       }
    }

}